/**
 * @author wangj881
 * @date 2025-02-27 10:15
 */
public class L24_3 {

    public static void main(String[] args) {
        ListNode node4 = new ListNode(4);
        ListNode node3 = new ListNode(3, node4);
        ListNode node2 = new ListNode(2, node3);
        ListNode node1 = new ListNode(1, node2);
        ListNode node = new Solution().swapPairs(node1);
        System.out.println(node.toString());

    }

    static class Solution {
        public ListNode swapPairs(ListNode head) {
            ListNode listNode = new ListNode(-1, head);
            ListNode one = listNode;
            while (one.next != null && one.next.next != null) {
                ListNode two = one.next;
                ListNode three = one.next.next;

                one.next = three;
                two.next = three.next;
                three.next = two;

                one = two;
            }
            return listNode.next;
        }
    }
}
